package com.hnkywl.sts.dao.tjbb;

import com.hnkywl.sts.entity.xsgl.Kh;
import net.ruixin.orm.hibernate.Page;
import net.ruixin.orm.hibernate.SimpleHibernateTemplate;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: lenovo
 * Date: 13-4-30
 * Time: 上午11:31
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class LrcsDao extends SimpleHibernateTemplate<Kh, Long> {

    public Page<Map> findLrcsList() {
        Page<Map> page = new Page<Map>();
        Map<String, Object> param = new HashMap<String, Object>();
        List<String> condition = new ArrayList<String>();
        String sqlBase = "select substr(t.month, 0, 4) as year, substr(t.month, 5, 2) as  month,t.ll as ll,t.bz  as bz from T_RPT_ZJZY_RATE t order by YEAR  DESC, MONTH  DESC ";
        String resultSql = sqlBase;
        List<Map> list = createSQLQuery(resultSql)
                .setProperties(param)
                .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
                .list();
        page.setResult(list);
        return page;
    }

    //修改
    public void updateLrcs(int mons, Float ll, Date lastUpdateDate, Long id) {
        String sql = "update T_RPT_ZJZY_RATE t set t.month = ?,t.ll = ?,t.upddt = ?,t.update_people = ?,t.bz = '已修改' where t.month = ?";
        createSQLQuery(sql, mons, ll, lastUpdateDate, id, mons).executeUpdate();
    }

}
